package com.star.tool.util;

import android.net.Uri;
import android.os.Build;
import android.support.v4.content.FileProvider;

import com.star.tool.Utils;

import java.io.File;

/**
 * Author: blackbai11
 * Date: 2016/2/18 10:11
 * Description:  Uri工具类
 */
public final class UriUtils {

    private UriUtils() {
        throw new UnsupportedOperationException("u can't instantiate me...");
    }

    /**
     * 获取文件 URI
     * Android 7.0以上获取Uri需要用到FileProvider（清单文件配置provider及xml）
     */
    public static Uri getUriForFile(final File file) {
        if (file == null) return null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            String authority = Utils.getApp().getPackageName() + ".utilcode.provider";
            return FileProvider.getUriForFile(Utils.getApp(), authority, file);
        } else {
            return Uri.fromFile(file);
        }
    }
}
